import unittest,requests
import logging
from one.Day4.log import log
class movie(unittest.TestCase):

    def setUp(self) -> None:
        log().Log2()

    def tearDown(self) -> None:
        pass

    @classmethod
    def setUpClass(cls) -> None:
        pass

    @classmethod
    def tearDownClass(cls) -> None:
        pass

    host='http://10.59.9.18'

    userId=None
    sessionId=None
    # 登录 login
    def test_01_login(self):
        logging.debug("这是一个debug日志")
        url=movie.host+'/movieApi/user/v2/login'
        json={"email":'1028374179@qq.com','pwd':'eWLPHopE945d2ivttHaQTQ=='}
        login=requests.post(url=url,data=json)
        print(login.json())
        movie.userId=login.json()['result']['userId']
        print(movie.userId)
        movie.sessionId=login.json()['result']['sessionId']
        print(movie.sessionId)

    #查询区域列表 regionlist
    regionId=None
    def test_02_RegionList(self):
        url = movie.host + '/movieApi/tool/v2/findRegionList'
        regionlist=requests.get(url=url)
        print(regionlist.json())
        movie.regionId=regionlist.json()['result'][0]['regionId']
        print(movie.regionId)

    # 查询热门电影列表 HotMovieList
    movieId = None
    def test_03_hotmovielist(self):
        url = movie.host + '/movieApi/movie/v2/findHotMovieList'
        json={'page':1,'count':5}
        hotmovielist=requests.get(url=url,params=json)
        print(hotmovielist.json())
        movie.movieId = hotmovielist.json()['result'][0]['movieId']
        print(movie.movieId)


    #根据电影id,区域id 查询播放影院信息  ByRegion
    cinemaId=None
    def test_04_cyregion(self):
        url=movie.host+'/movieApi/movie/v2/findCinemasInfoByRegion'
        headers = {"userId": str(movie.userId), 'sessionId': movie.sessionId}
        json={'movieId': movie.movieId,'regionId':movie.regionId,'page':1,'count':5}
        cyregion=requests.get(url=url,headers=headers,params=json)
        print(cyregion.json())
        movie.cinemaId=cyregion.json()['result'][0]['cinemaId']
        print(movie.cinemaId)

    #根据电影ID和影院ID查询电影排期列表 Schedule
    scheduleId=None
    def test_05_schedule(self):
        url=movie.host+'/movieApi/movie/v2/findMovieSchedule'
        headers = {"userId": str(movie.userId), 'sessionId': movie.sessionId}
        json={'movieId': movie.movieId,'cinemaId':movie.cinemaId}
        schedule=requests.get(url=url,headers=headers,params=json)
        print(schedule.json())
        movie.scheduleId=schedule.json()['result'][0]['id']
        print(movie.scheduleId)

    #购票下单 care
    def test_06_care(self):
        url = movie.host + '/movieApi/movie/v2/verify/buyMovieTickets'
        headers={"userId":str(movie.userId),'sessionId':movie.sessionId}
        json={'scheduleId':str(movie.scheduleId),'seat':["3-7","3-8"],'sign':"c805fef81048abfdbbbf9b90fb2e0696"}
        care=requests.post(url=url,headers=headers,data=json)
        print(care.json())

if __name__ == '__main__':
    unittest.main()